package top.v5it.japi.ddd.example.member.service.impl;

import cn.hutool.core.lang.Assert;
import org.springframework.stereotype.Service;
import top.v5it.japi.ddd.core.dao.impl.BasicDaoJdbcImpl;
import top.v5it.japi.ddd.core.service.impl.BasicServiceImpl;
import top.v5it.japi.ddd.example.member.entity.Member;
import top.v5it.japi.ddd.example.member.service.MemberService;

import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * 具体会员服务
 *
 * @author zhanpu
 * @date 2023/10/26
 */
@Service(MemberService.SERVICE_NAME)
public class MemberServiceImpl extends BasicServiceImpl<BasicDaoJdbcImpl> implements MemberService {
    @Override
    public void registration(Member entity) {
        Assert.notNull(entity, "请求参数[entity]不能为空");
        // 设置注册时间
        entity.setRegistration_date(LocalDateTime.now(ZoneId.systemDefault()));
        // 注册赠送50积分
        entity.setTotal_points(50);
        basicDao.insert(entity);
    }

    @Override
    public void modify(Member entity) {
        Assert.notNull(entity, "请求参数[entity]不能为空");
        basicDao.update(entity);
    }

    @Override
    public Member searchById(Long id) {
        Assert.notNull(id, "请求id不能为空");
        return basicDao.load(id, new Member());
    }

}
